import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class TestChromeConnection {
    public static void main(String[] args) {
        System.out.println("开始测试Chrome连接...");
        
        // 设置ChromeDriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Windows\\chromedriver.exe");
        
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
        options.addArguments("--disable-blink-features=AutomationControlled");
        options.addArguments("--disable-extensions");
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");
        
        try {
            System.out.println("尝试连接Chrome调试实例...");
            WebDriver driver = new ChromeDriver(options);
            System.out.println("✅ 成功连接到Chrome调试实例！");
            
            // 测试导航
            System.out.println("测试导航到百度...");
            driver.get("https://www.baidu.com");
            System.out.println("✅ 导航成功！当前页面标题: " + driver.getTitle());
            
            Thread.sleep(3000);
            driver.quit();
            System.out.println("✅ 测试完成！");
            
        } catch (Exception e) {
            System.out.println("❌ 连接失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}



